package br.edu.unifei.mestrado.fm;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NetList implements Iterable<Net> {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	private Map<Long, Net> map = new HashMap<Long, Net>();

	private static long idNetGlobal = 0L;

	@Override
	public Iterator<Net> iterator() {
		return map.values().iterator();
	}

	public Net getElementAt(Long indice) {
		return map.get(indice);
	}

	public Net createNet(Cell cell1, Cell cell2) {

		Net net = new Net();
		net.setId(idNetGlobal);
		net.setCell1(cell1);
		net.setCell2(cell2);
		this.insert(net);

		idNetGlobal++;
		return net;
	}

	public void insert(Net valor) {
		map.put(valor.getId(), valor);
	}

	public void imprimeLista() {
		logger.info("NetList ({}): ", map.size());
		for (Net net : map.values()) {
			logger.debug("N " + net.getId() + ": C" + net.getCell1().getId() + " C" + net.getCell2().getId());
		}
	}

	public int size() {
		return map.size();
	}
}
